QuickOPC User's Guide and Reference
Examples - OPC XML-DA - Subscribe with a callback
View with Navigation Tools
// This example shows how subscribe to changes of a single item in an OPC XML-DA server and display the value of the item 
// with each change, using a callback method specified using lambda expression.

using System;
using System.Threading;
using System.Diagnostics;
using OpcLabs.EasyOpc.DataAccess;

namespace DocExamples.DataAccess.Xml
{
    class SubscribeItem
    {
        public static void CallbackLambdaXml()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            Console.WriteLine("Subscribing item...");
            // The callback is a lambda expression the displays the value
            client.SubscribeItem(
                "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx",
                "Dynamic/Analog Types/Int",
                1000,
                (sender, eventArgs) =>
                {
                    Debug.Assert(eventArgs != null);

                    if (eventArgs.Succeeded)
                    {
                        Debug.Assert(eventArgs.Vtq != null);
                        Console.WriteLine(eventArgs.Vtq.ToString());
                    }
                    else
                        Console.WriteLine($"*** Failure: {eventArgs.ErrorMessageBrief}");
                },
                state: null);

            Console.WriteLine("Processing item changed events for 30 seconds...");
            Thread.Sleep(30 * 1000);

            Console.WriteLine("Unsubscribing items...");
            client.UnsubscribeAllItems();

            Console.WriteLine("Waiting for 2 seconds...");
            Thread.Sleep(2 * 1000);

            Console.WriteLine("Finished.");
        }
    }
}
It is also possible to specify lambda function as a callback in Python.NET, but because lambda functions are limited to an expression in Python, the usability of this approach is limited.

 

QuickOPC supports OPC XML-DA also on Linux and macOS.
See Also

Examples - OPC Data Access

Conceptual